<?php 

class HModuleAdmin {
	/**
	 * CRUD
	 */
	function insert($name, $create_date = null, $create_user = null, $modify_date = null, $modify_user = null) {
		try {
			$a = HSql::doQuery(
				"INSERT INTO portal_modules(module_name, created_date, created_user, modified_date, modified_user) 
				VALUES(
					'$name',
					'$create_date',
					'$create_user',
					'$modify_date',
					'$modify_user'
				)");
			// Get the last id
			$id = mysql_insert_id();			
			// Insert default view		
			HModuleInstanceAdmin::insert($id, 'index.php','index');	
		}
		catch (Exception $ex) {
			throw new Exception($ex->getMessage());
		}
	}
	
	function update($id, $name, $modify_date, $modify_user) {
		try {
			HSql::doQuery(
				"UPDATE portal_modules 
				SET
					name = '$name', 
					modified_date = '$modify_date',
					modified_user = '$modify_user'
				WHERE id = '$id'"
			);
		}
		catch (Exception $ex) {
			throw new Exception($ex->getMessage());
		}
	}
	
	function delete($id) {
		try {
			HSql::doQuery("DELETE FROM portal_modules WHERE id = '$id'");
		}
		catch (Exception $ex) {
			throw new Exception($ex->getMessage());
		}
	}	
}